import DataUtil as dataUtil
import Algorithm as alg
import Util as util
import Config as conf

# init operation
util.create_directory('caches')
util.create_directory('data')
util.create_directory('results')

# test
calcTestResult = False
if calcTestResult:
    print("loading test data...")
    id_array, x_test = dataUtil.get_test_data()

    print("calc test result...")
    clf = alg.get_model_by_file(alg.LINEAR_MODEL_PATH)
    y_array = clf.predict(x_test)

    print("create result csv file")
    dataUtil.get_result_csv_file(id_array, y_array)

    print("mission complete!")

# train
else:
    # data
    print("loading data...")
    nrow_train, X_all, y_train = dataUtil.get_data()

    # x_train
    x_train_train = X_all[:nrow_train][:conf.TEST_SIZE]
    y_train_train = y_train[:conf.TEST_SIZE]
    x_train_test = X_all[:nrow_train][conf.TEST_SIZE:]
    y_train_test = y_train[conf.TEST_SIZE:]

    # regression
    print("predicting...")
    # y_predict = alg.svr(x_train, y_train, x_test)
    y_predict = alg.linear(x_train_train, y_train_train, x_train_test)

    # error
    print("calc error...")
    print("error: {}".format(alg.rmsle(y_predict, y_train_test)))

